package com.crm.framework.config;

import com.crm.common.util.PathUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author luojie
 * @date 2020/10/21 9:13
 */
@Configuration
public class WebAppConfig extends WebMvcConfigurationSupport {

    @Value("${file.staticAccessPath}")
    private String staticAccessPath;

    /**
     * 在配置文件中配置的文件保存路径
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String uploadFolder = PathUtil.getBasePath();
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);
        super.addResourceHandlers(registry);
    }

}
